package wsi.task.typedetector;

import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class AbstractDetector {
	protected final Logger log = Logger.getLogger(getClass().getName());

	protected final String name;
	protected Pattern[] patterns;

	protected AbstractDetector(String name) {
		this.name = name;
	}

	public double detect(List<String> values) {
		int succ = 0;

		if (patterns != null)
			for (String i : values) {
				for (Pattern j : patterns) {
					Matcher m = j.matcher(i);

					if (m.find()) {
						succ++;
						break;
					}
				}
			}

		return 1. * succ / values.size();
	}

	public String getName() {
		return name;
	}

	protected void setPatterns(Pattern[] patterns) {
		this.patterns = patterns;
	}
}
